enum LoginType {
  Local = 'local',
  RworkSSO = 'sso-rwork'
}

console.log('isDev Mode:', import.meta.env.DEV)
console.log('env:', import.meta.env)

const rworkConfigs: Record<string, any> = {
  uat: {
    env: 'uat',
    logo_src: 'rwork-logo.png',
    logo_slogan: '欢迎来到数科员工助手',
    chat_become_home: false,
    home_recommend_agent_keys: [
      'it_tech',
      'work_summary',
      'ppt_outline',
      'excel_formula',
      'manuscript_proofreading',
      'hackathon'
    ],
    hidden_home_new_chat_button: false,
    // ai_login_type: LoginType.RworkSSO,
    rwork_env: 'uat',
    rwork_app_id: 'cli_a65aae6b6737908f',
    hidden_chat_bg: true,
    default_agent_id: 'llm',
    default_agent_name: '华润数科私域大模型'
  },
  prd: {
    env: 'prd',
    logo_src: 'rwork-logo.png',
    logo_slogan: '欢迎来到数科员工助手',
    chat_become_home: false,
    home_recommend_agent_keys: [
      'it_tech',
      'work_summary',
      'ppt_outline',
      'excel_formula',
      'manuscript_proofreading',
      'hackathon'
    ],
    hidden_home_new_chat_button: false,
    ai_login_type: LoginType.RworkSSO,
    rwork_env: 'production',
    rwork_app_id: 'cli_a65b9bc42ab8d08f',
    hidden_chat_bg: true,
    default_agent_id: 'llm',
    default_agent_name: '华润数科私域大模型'
  }
}

const crpowerConfigs: Record<string, any> = {
  uat: {
    env: 'uat',
    logo_src: 'logo.png',
    logo_slogan: '欢迎来到华润电力AI助手',
    chat_become_home: false,
    home_recommend_agent_keys: [
      'intelligent_authoring',
      'purchase_order_generate',
      'feasibility_report_review',
      'data_analysis',
      'knowledge_qa',
      'power_industry_news'
    ],
    hidden_home_new_chat_button: false,
    ai_login_type: LoginType.RworkSSO,
    rwork_env: 'uat',
    rwork_app_id: 'cli_xxx',
    hidden_chat_bg: false,
    default_agent_id: 'llm',
    default_agent_name: '华润电力私域大模型'
  },
  prd: {
    env: 'prd',
    logo_src: 'logo.png',
    logo_slogan: '欢迎来到华润电力AI助手',
    chat_become_home: false,
    home_recommend_agent_keys: [
      'intelligent_authoring',
      'purchase_order_generate',
      'feasibility_report_review',
      'data_analysis',
      'knowledge_qa',
      'power_industry_news'
    ],
    hidden_home_new_chat_button: false,
    ai_login_type: LoginType.RworkSSO,
    rwork_env: 'production',
    rwork_app_id: 'cli_xxxx',
    hidden_chat_bg: false,
    default_agent_id: 'llm',
    default_agent_name: '华润电力私域大模型'
  }
}

const configs: Record<string, any> = {
  rwork: rworkConfigs,
  crpower: crpowerConfigs
}

//没有对应变量时的默认值
const envType = (import.meta.env.VITE_APP_ENV as string) || 'uat'
const clientKey = (import.meta.env.VITE_CUSTOMER as string) || 'rwork'

const EnvConfig = {
  ...configs[clientKey][envType]
}
export function getConfigForKey(key?: string) {
  if (!key) {
    return EnvConfig
  }
  // console.log(`EnvConfig[${key}]`, EnvConfig[key])
  return EnvConfig && EnvConfig[key]
}

const userAgent = navigator.userAgent.toLowerCase()

console.info('userAgent', userAgent)

export const isRelease = import.meta.env.PROD

export const homeLogoPath = getConfigForKey('logo_src')

export const isInLarkApp = userAgent.includes('lark')
export const isSSORwork = getConfigForKey('ai_login_type') === LoginType.RworkSSO && isInLarkApp

export const isHiddenHomeNewChatButton = getConfigForKey('hidden_home_new_chat_button')
export const isHiddenChatBg = getConfigForKey('hidden_chat_bg')
export const defaultAgentId = getConfigForKey('default_agent_id')
export const defaultAgentName = getConfigForKey('default_agent_name')

export default EnvConfig
